/*
package com.ck.hxc.controller;

import com.iflytek.cloud.speech.RecognizerListener;
import com.iflytek.cloud.speech.RecognizerResult;
import com.iflytek.cloud.speech.SpeechError;
import com.iflytek.cloud.speech.SpeechRecognizer;
import com.iflytek.cloud.speech.SpeechUtility;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@RestController
public class VoiceController {

    public VoiceController() {
        // 初始化科大讯飞 SDK（确保 AppID 正确）
        SpeechUtility.createUtility("appid=5c7c8479");
    }

    @PostMapping("/upload")
    public String uploadAudio(@RequestParam("file") MultipartFile file) {
        try {
            // 1. 保存音频文件
            String filePath = "C:/audio/" + file.getOriginalFilename();
            File dest = new File(filePath);
            file.transferTo(dest);

            // 2. 处理语音识别
            return processAudio(filePath);
        } catch (Exception e) {
            return "上传失败：" + e.getMessage();
        }
    }

    */
/**
     * 语音识别方法
     *//*

    private String processAudio(String filePath) {
        SpeechRecognizer recognizer = SpeechRecognizer.createRecognizer();
        StringBuilder resultText = new StringBuilder();

        // 设置语音识别监听器
        recognizer.setParameter("audio_source", "audio");
        recognizer.setParameter("asr_audio_path", filePath);
        recognizer.startListening(new RecognizerListener() {
            @Override
            public void onBeginOfSpeech() {
                System.out.println("开始语音识别...");
            }

            @Override
            public void onEndOfSpeech() {
                System.out.println("语音识别结束");
            }

            @Override
            public void onResult(RecognizerResult results, boolean isLast) {
                String text = parseResult(results);
                System.out.println("识别结果：" + text);
                resultText.append(text);
            }

            @Override
            public void onVolumeChanged(int volume) {
                System.out.println("音量：" + volume);
            }

            @Override
            public void onError(SpeechError error) {
                System.err.println("语音识别错误：" + error.getErrorDescription(true));
            }

            @Override
            public void onEvent(int eventType, int arg1, int arg2, String msg) {
                System.out.println("事件回调：" + eventType + ", 消息：" + msg);
            }
        });

        // 等待识别完成
        try {
            Thread.sleep(5000);  // 等待5秒，防止识别未完成
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return resultText.toString();
    }

    */
/**
     * 解析语音识别结果
     *//*

    private String parseResult(RecognizerResult results) {
        return results.getResultString();  // 直接返回 JSON 结果
    }
}
*/
